//用ufds中保存的key进行加密解密的服务
var sdc = require('sdc-clients'),
dc_config=require('./config').poc,
crypto = require('crypto'),
SecureToken = require('sdc-securetoken')
ufds = new sdc.UFDS(dc_config.ufds)
		var finish = function (entries) {
			tokenizer = new SecureToken(entries[0], entries)
			tokenizer.encrypt({foo: 'bar',baz: [1, 2, 3]}, function (err, securetoken) {
				console.log(securetoken)
				tokenizer.decrypt(securetoken,function (err2, data) {
					console.log(data)
				})
			})
		}
ufds.search('ou=keyapiprivkeys, o=smartdc', 
	{scope: 'sub',filter: '(objectclass=keyapiprivkey)'}, function (err, entries) {
		if (entries.length > 0)
			return finish(entries);
		var hex  = crypto.randomBytes(32).toString('hex');
		var date = new Date().toISOString();

		var ufdsEntry = {
		   uuid: Math.round(Math.random()*1000000),
		   key: hex,
		   timestamp: date,
		   objectclass: 'keyapiprivkey'
		}
		var dn = 'dn=' + ufdsEntry.uuid + ', ou=keyapiprivkeys, o=smartdc';
		return ufds.add(dn, ufdsEntry, function (err2) {finish([ufdsEntry])})

})